import SettingsData from "../data/SettingsData"

export default class SettingsToggler {
  settings: Record<string, boolean>
  cache: Record<string, boolean>
  settingsData: SettingsData
  constructor(e, t) {
    this.settingsData = e
    this.settings = t
    this.cache = {}
  }
  apply() {
    this.cache = {}
    for (const e of Object.keys(this.settings)) {
      const t = this.settingsData.tryGetProperty(e, void 0)
      t !== this.settings[e] && ((this.cache[e] = t), this.settingsData.setProperty(e, this.settings[e]))
    }
  }
  reset() {
    for (const e of Object.keys(this.cache)) {
      const t = this.cache[e]
      this.settingsData.setProperty(e, void 0 !== t && t)
    }
    this.cache = {}
  }
  toggle(e: boolean) {
    e ? this.apply() : this.reset()
  }
}
